// pages/userCenter/userCenter.js
var app = getApp()
const utils = require('../../utils/util')

Page({

  /**
   * 页面的初始数据
   */
  data: {
    showBtn: true,
    showCode: true,
    QRsrc: '',
    gender: 1,
    tel: '',
    car_no: '',
    isStaff: false
  },
  toChangePw: function() {
    wx.navigateTo({
      url: '../userCenter/changePw/changePw'
    })
  },
  toAddress: function() {
    wx.navigateTo({
      url: '../userCenter/myAddress/myAddress'
    })
  },
  toChooseCar: function() {
    wx.navigateTo({
      url: '../userCenter/chooseCar/chooseCar'
    })
  },
  toMoneyBox: function() {
    wx.navigateTo({
      url: '../userCenter/moneyBox/moneyBox',
    })
  },
  toqianbao: function(){
    wx.navigateTo({
      url: '../userCenter/myTeam/myTeam'
    })
  },
  toMyTeam: function() {
    wx.navigateTo({
      url: '../userCenter/myTeam/myTeam'
    })
  },
  goMyOrders: function(e) {
    const oid = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '../userCenter/myOrders/myOrders?oid=' + oid,
    })
  },
  toCarNote: function() {
    wx.navigateTo({
      url: '../userCenter/myCarNote/myCarNote',
    })
  },
  topingjia: function() {
    wx.navigateTo({
      url: '../userCenter/pingjiaManager/pingjiaManager',
    })
  },
  tomyHouse: function() {
    wx.navigateTo({
      url: '../userCenter/myHouse/myHouse',
    })
  },
  toGZDnote: function() {
    wx.navigateTo({
      url: '../userCenter/myGZDnote/myGZDnote',
    })
  },
  tonewsWarn: function() {
    wx.navigateTo({
      url: '../userCenter/newsWarn/newsWarn',
    })
  },
  toShare: function() {
    wx.navigateTo({
      url: '../userCenter/share/share',
    })
  },
  toNearby: function() {
    wx.navigateTo({
      url: '../userCenter/nearby/nearby',
    })
  },
  toServer: function() {
    wx.navigateTo({
      url: '../userCenter/server/server',
    })
  },
  toJD: function() {
    wx.navigateTo({
      url: '../userCenter/jiedan/jiedan',
    })
  },
  toMycarinfo(){
    wx.navigateTo({
      url: '../userCenter/myCarinfo/myCarinfo',
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function() {
    this.setData({
      isStaff: utils.isStaff()
    })
  },

  // 商家注册
  toMerchant() {
    wx.navigateTo({
      url: './merchantReg/merchantReg'
    })
  },

  // 写评论
  toComment() {
    wx.navigateTo({
      url: './comment/comment'
    })
  },

  // 获取二维码
  getCode: function() {
    var that = this;
    wx.request({
      url: app.d.severUrl + '/Member/getQrcode',
      data: {
        member_id: app.d.getMemberData.member_id
      },
      method: 'post',
      header: {
        "Content-Type": "application/x-www-form-urlencoded"
      },
      success: function(res) {
        if (res.data.code == 0) {
          that.data.showBtn = false;
          that.data.showCode = true;
          that.setData({
            showBtn: that.data.showBtn,
            showCode: that.data.showCode,
          })

        } else {
          that.data.QRurl = app.d.QRUrl + res.data.data;

          that.data.showBtn = true;
          that.data.showCode = false;
          that.setData({
            QRsrc: that.data.QRurl,
            showBtn: that.data.showBtn,
            showCode: that.data.showCode,
          })
          app.d.QRsrc = that.data.QRurl;
          app.d.QRname = res.data.data;
        }
      }
    })
  },
  //点击放大图片
  previewImage: function(e) {
    wx.previewImage({
      urls: this.data.QRsrc.split(',')
    })
  },
  //我的挪车卡
  toMyCard: function() {
    wx.navigateTo({
      url: 'myCard/myCard'
    })
  },
  //设置
  toSet: function() {
    wx.navigateTo({
      url: 'set/set'
    })
  },
  logout() {
    wx.showModal({
      title: '提示',
      content: '确定退出登录吗？',
      success: res => {
        if (res.confirm) {
          wx.clearStorageSync()
          wx.reLaunch({
            url: '/pages/index/login/login'
          })
        }
      }
    })
  },
  onShareAppMessage: function() {
    return {
      title: '分享挪车标给好友，激活全部功能',
      path: '/pages/index/index?pid=' + app.d.getMemberData.member_id,
      success: function(res) {
        // 转发成功
      },
      fail: function(res) {
        // 转发失败
      }
    }
  },
})